# encoding=utf-8

from tkinter import *

root = Tk();root.geometry("530x300")
c1 = Canvas(root, width=200, height=200, bg="green")
c1.pack()

class Application(Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.createWidget()

    def createWidget(self):
        # self.photo = PhotoImage(file="imgs/logo.gif")
        # self.puke1 = Label(self.master, image=self.photo)
        # self.puke1.place(x=10,y=50)

        self.photos = [PhotoImage(file="imgs/logo"+ str(i+1) +".gif") for i in range(10)]
        self.pukes = [Label(self.master, image=self.photos[i]) for i in range(10)]

        for i in range(10):
            self.pukes[i].place(x=10+i*40, y=50)

        self.pukes[0].bind_class("Label","<Button-1>", self.chupai)

    def chupai(self,event):
        print(event.widget.winfo_geometry())
        print(event.widget.winfo_y())

        if event.widget.winfo_y() == 50:
            event.widget.place(y=30)
        else:
            event.widget.place(y=50)

    def mouseTest(event):
        print("鼠标左键单击位置（相对于父容器）:{0},{1}".format(event.x, event.y))
        print("鼠标左键单击位置(相对于屏幕):{0},{1}".format(event.x_root, event.y_root))
        print("事件绑定的组件:{0}".format(event.widget))

    def testDrag(event):
        c1.create_oval(event.x, event.y, event.x+1, event.y+1)

    def keyboardTest(event):
        print("键的keycode:{0},键的char:{1},键的keysym:{2}".format(event.keycode, event.char, event.keysym))

    def press_a_test(event):
        print("press a")

    def release_a_test(event):
        print("release a")

    c1.bind("<Button-1>", mouseTest)

    c1.bind("<B1-Motion>", testDrag)

    root.bind("<KeyPress>", keyboardTest)
    root.bind("<KeyPress-a>", press_a_test)
    root.bind("<KeyRelease-a>", release_a_test)

if __name__ == '__main__':
    root = Tk()
    root.geometry("200x200+200+300")
    root.title("扑克牌")
    app = Application(master=root)
    root.mainloop()
